<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( '../global/initialize.php' );
aos_header( 'Promotion' );
global $dal, $premium;
$statement = $dal->prepare( 'SELECT promotion_points, became_fan, username, pbbg_warp_random, users.user_id ' .
		'FROM users ' .
		'JOIN ruler ON ruler.user_id = users.user_id ' .
		'WHERE ruler_id = :ruler_id' );
$statement->bindParam( ':ruler_id', $_SESSION[ 'ruler_id' ], PDO::PARAM_INT );
$userSettings = $dal->getObject( $statement );
$promotionPoints = $userSettings->promotion_points;
if( $premium < 1 ) {
	$premiumTurns = translate( 'None' );
}
else {
	$premiumTurns = number_format( $premium );
}
?>
					<div class="blok">
						<strong><?php transprint( 'What can I do here?' ); ?></strong><br />
						<?php transprint( 'The promotion page allows you to perform promotion activities for Ages of Strife and receive promotion points as reward.' ); ?><br />
						<?php transprint( 'Promotion points can be exchanged for premium turns, the more promotion points you exchange at once the more bonus premium turns you will get.' ); ?><br />
						<br />
<?php
	$statement = $dal->prepare( 'SELECT SUM( reward ) ' .
			'FROM vote_reward ' .
			'WHERE timestamp >= :timestamp' );
	$timestamp = time() - 86400;
	$statement->bindParam( ':timestamp', $timestamp, PDO::PARAM_INT );
	$lastDayPromotion = $dal->getValue( $statement );
	$timestamp = time() - 604800;
	$lastWeekPromotion = $dal->getValue( $statement );
	$timestamp = time() - 2592000;
	$lastMonthPromotion = $dal->getValue( $statement );
	$timestamp = -1;
	$allTimePromotion = $dal->getValue( $statement );
?>
						<strong><?php transprint( 'Rewarded promotion points' ); ?></strong><br />
						<?php transprint( 'Past 24 hour' ); ?>: <?php print( number_format( $lastDayPromotion ) ); ?><br />						
						<?php transprint( 'Past week' ); ?>: <?php print( number_format( $lastWeekPromotion ) ); ?><br />						
						<?php transprint( 'Past month' ); ?>: <?php print( number_format( $lastMonthPromotion ) ); ?><br />						
						<?php transprint( 'All time' ); ?>: <?php print( number_format( $allTimePromotion ) ); ?><br />						
					</div>
					<br />
<?php
	if( isset( $_SESSION[ 'promotion_exchange_status' ] ) ) {
?>
					<div class="blok">
						<strong><?php transprint( 'Status' ); ?></strong>: <?php print( $_SESSION[ 'promotion_exchange_status' ] ); ?>
					</div>
					<br />
<?php
		unset( $_SESSION[ 'promotion_exchange_status' ] );
	}
?>
					<div class="blok">
						<strong><?php transprint( 'Promotion points' ); ?></strong><br />
						<?php transprint( 'Promotion points' ); ?>: <?php print( number_format( $promotionPoints ) ); ?><br />
						<form method="post" action="get_premium_turns.php">
							<input type="radio" name="exchange" value="100" id="exchange-100" /> <label for="exchange-100"><?php transprint( 'Exchange' ); ?> 100 <?php transprint( 'promotion points for' ); ?> 20 <?php transprint( 'premium turns' ); ?></label><br /> 
							<input type="radio" name="exchange" value="1000" id="exchange-1000" /> <label for="exchange-1000"><?php transprint( 'Exchange' ); ?> 1,000 <?php transprint( 'promotion points for' ); ?> 200 <?php transprint( 'premium turns' ); ?> (+10 <?php transprint( 'premium turns' ); ?> <?php transprint( 'bonus' ); ?>)</label><br /> 
							<input type="radio" name="exchange" value="10000" id="exchange-10000" /> <label for="exchange-10000"><?php transprint( 'Exchange' ); ?> 10,000 <?php transprint( 'promotion points for' ); ?> 2,000 <?php transprint( 'premium turns' ); ?> (+200 <?php transprint( 'premium turns' ); ?> <?php transprint( 'bonus' ); ?>)</label><br />
							<input type="submit" value="<?php transprint( 'exchange' ); ?>" /><br />
						</form>
						<?php transprint( 'Premium turns' ); ?>: <?php print( $premiumTurns ); ?><br />
						<br />
						<?php transprint( 'Or buy premium turns at the' ); ?> <a href="../global/shop.php"><strong><?php transprint( 'premium turns shop' ); ?></strong></a>.
					</div>
					<br />
					<div class="blok">
						<strong><?php transprint( 'Promote' ); ?></strong><br />
<?php
if( $userSettings->became_fan == -1 ) {
	// User is not a fan yet! So we offer a link to become a fan of AoS on PBBG Warp
	if( $userSettings->pbbg_warp_random == -1 ) {
		$userSettings->pbbg_warp_random = 1000000000 + rand( 0, 999999999 );
		$statement = $dal->prepare( 'UPDATE users ' .
				'SET pbbg_warp_random = :random_key ' .
				'WHERE user_id = :user_id' );
		$statement->bindParam( ':random_key', $userSettings->pbbg_warp_random, PDO::PARAM_INT );
		$statement->bindParam( ':user_id', $_SESSION[ 'user_id' ], PDO::PARAM_INT );
		$dal->execute( $statement );
	}
?>
						<?php transprint( 'Become a fan of Ages of Strife on PBBG Warp and receive 100 promotion points' ); ?>:<br />
						<a href="http://www.pbbgwarp.com/pbbg/fanform.php?id=88&screenname=<?php print( $userSettings->username ); ?>&key=<?php print( $userSettings->pbbg_warp_random ); ?>"><?php transprint( 'Become fan' ); ?></a><br />
						<br />
<?php
}
?>
						<?php transprint( 'Vote for Ages of Strife on the following sites for 5 promotion points per vote. You can vote every hour.' ); ?><br />
						<script type="text/javascript">
						<!--
						var pwsat_params = [];
						pwsat_params['id'] = 88;
						pwsat_params['userid'] = '<?php print( $userSettings->user_id ); ?>'; // Do not URL encode
						//-->
						</script>
						<script type="text/javascript" src="http://remote.pbbgwarp.com/js/votelinks.js"></script>
						<br />
						<br />
						<?php transprint( 'Do you want to promote Ages of Strife in a different way and hope to get a reward?' ); ?><br />
						<?php transprint( 'Click' ); ?> <a href="mailto:contact@agesofstrife.com"><?php transprint( 'here' ); ?></a> <?php transprint( 'to propose a promotion deal by e-mail' ); ?>.
					</div>
<?php

$addedJavaScript = <<<JAVASCRIPT
		<script type="text/javascript">
			function waitChangeLinks() {
				setTimeout( "changeLinks()", 500 );
			}
			
			function changeLinks() {
				var links = YAHOO.util.Dom.getElementsByClassName( "pwsat_link" );
				for( var i in links ) {
					links[i].target = "_blank";
				}
			}
			
			YAHOO.util.Event.addListener( window, "load", waitChangeLinks );
		</script>
JAVASCRIPT;

aos_footer( $addedJavaScript );
?>